<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/1 0001
 * Time: 10:35
 */

namespace app\api\controller\v1\cleaner;


use app\api\controller\v1\Cleaner;
use app\currency\service\CleanerService;
use think\Db;

class Home extends Cleaner
{
    /**
     * 返回首页面板所需数据
     * 订单数量信息（待接单、待服务）、账户余额、绑定地址数量、团队人数、个人信息
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        $CleanerService = new CleanerService();
        //团队数量
        $teamNum = $CleanerService::getTeamNum($this->cid,2,true);
        //绑定地址数量
        $bindAddNum = $CleanerService::getBindAddNum($this->cid);
        //待接单订单数量
        $order_waiting_for_taking_num = $CleanerService::getOrderTaking($this->cid);
        //待服务订单数量
        $order_waiting_for_service_num = Db::name('CleanOrder')
            ->where('cid','eq',$this->cid)
            ->whereIn('status',['2','3'])
            ->count();
        $result = [
            'team_num' => $teamNum,
            'bind_add_num' => $bindAddNum,
            'order_waiting_for_taking_num' => $order_waiting_for_taking_num,
            'order_waiting_for_service_num' => $order_waiting_for_service_num,
            'customer_service_telephone_numbers' => sysconf('customer_service_telephone_numbers') ?: '',
            'cleaner' => $this->cleaner,
            'wechat_qrcode' => sysconf('wechat_qrcode'),
        ];
        $this->success('success',$result);
    }
}